Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: yield scheduler when blocked #22

Merged
merged 4 commits into from
Apr 6, 2024

Conversation

shenyih0ng
Copy link
Owner

@shenyih0ng shenyih0ng commented Apr 6, 2024

Description

This PR implements the optimisation by yielding scheduler time to other goroutines if the current one is blocked. Previously goroutines take up the entire time quantum even if it was blocked, preventing other idle goroutines from executing.

Additionally, I have also added an naive deadlock detection mechanism, exiting from the program if all goroutines are blocked. However because of how syncing process of unbuffered channels work, we cannot simply exit the moment the scheduler sees that all goroutines are blocked. This is because during the syncing process of unbuffered channels, both the sender and receiver will be blocked, but progress is being made. Therefore, to detect deadlocks, we are checking for N consecutive cycles where all N goroutines are blocked before exiting and erroring.

I have also added a @benchmark decorator for testing our scheduler

@shenyih0ng shenyih0ng self-assigned this Apr 6, 2024
@shenyih0ng shenyih0ng marked this pull request as ready for review April 6, 2024 16:40
@shenyih0ng shenyih0ng merged commit 6c72359 into master Apr 6, 2024
1 check passed
@shenyih0ng shenyih0ng deleted the feat/goroutine-yield-when-blocked branch April 6, 2024 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant